package com.zkthink.ceres.app.promotion.controller;

import com.zkthink.base.R;
import com.zkthink.ceres.common.annotations.LoginMode;
import com.zkthink.ceres.promotion.dto.CouponIdDTO;
import com.zkthink.ceres.promotion.entity.Promotion;
import com.zkthink.ceres.promotion.service.MemberCouponService;
import com.zkthink.ceres.promotion.service.PromotionService;
import com.zkthink.ceres.promotion.vo.web.CouponPageVO;
import com.zkthink.ceres.promotion.vo.web.PromotionVO;
import com.zkthink.context.BaseContextHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Validated
@AllArgsConstructor
@RestController
@RequestMapping("/promotion")
@Api(value = "营销活动接口", tags = "营销活动服务")
public class PromotionController {

    private PromotionService promotionService;

    private MemberCouponService memberCouponService;

    @GetMapping("/findPromotionList/{promotionIds}")
    @LoginMode(strict = false)
    @ApiOperation("批量查询营销活动")
    public R<List<PromotionVO>> findPromotionList(@PathVariable("promotionIds") String promotionIds){
        Long mid = BaseContextHandler.getUserId();
        return promotionService.findPromotionList(mid,promotionIds);
    }

    @PostMapping("/receiveCoupon")
    @ApiOperation("领券接口")
    public R<Boolean> receiveCoupon(@RequestBody CouponIdDTO couponIdDTO){
        Long mid = BaseContextHandler.getUserId();
        return memberCouponService.receiveCoupon(mid,couponIdDTO.getId());
    }

    @GetMapping("/findCouponList")
    @ApiOperation("查询优惠券列表")
    public R<CouponPageVO> findCouponList(@RequestParam Integer pageIndex, @RequestParam Integer pageSize){
        Long mid = BaseContextHandler.getUserId();
        return memberCouponService.findCouponList(mid,pageIndex,pageSize);
    }

}
